package com.koron.common.core.interceptor;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author jzp
 * @since 2021/9/27
 */
@Component
public class FieldAdapterRegister implements InitializingBean {

    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public void afterPropertiesSet() {
        // 注册FieldAdapter
        Map<String, FieldAdapter> fieldAdapterMap = applicationContext.getBeansOfType(FieldAdapter.class);
        for (FieldAdapter value : fieldAdapterMap.values()) {
            for (String field : value.fields()) {
                Adapters.register(field, value);
            }
        }
    }
}
